var event = require('../../utils/eventManager.js');

var index;

Page({
    data: {
        bold: "normal",
        middle: "left",
        font_size: {
            font_size: "28rpx",
            top: "20rpx",
            left: "245rpx",
            height: "40rpx",
            width: "40rpx"
        },
        bold_icon: "../../resource/editor/bold1.png",
        middle_icon: "../../resource/editor/left.png",
        size_icon: "../../resource/editor/text.png",
        text: ""
    },
    onLoad(e) {
        index = e.index;
    },
    textchange(e) {
        this.setData({
            text: e.detail.value
        })
    },
    changeText() {
        var obj = {
            bold: this.data.bold,
            middle: this.data.middle,
            font_size: this.data.font_size.font_size,
            text: this.data.text
        }

        event.fireEvent("editor", {
            index: index,
            data: obj
        })

        wx.navigateBack();
    },
    onBold() {
        if (this.data.bold == "normal") {
            this.setData({
                bold: "bold",
                bold_icon: "../../resource/editor/bold.png"
            })
        } else {
            this.setData({
                bold: "normal",
                bold_icon: "../../resource/editor/bold1.png"
            })
        }
    },
    onMiddle() {
        if (this.data.middle == "left") {
            this.setData({
                middle: "center",
                middle_icon: "../../resource/editor/middle.png"
            })
        } else {
            this.setData({
                middle: "left",
                middle_icon: "../../resource/editor/left.png"
            })
        }
    },
    onFontSize() {
        if (this.data.font_size.font_size == "28rpx") {
            this.setData({
                font_size: {
                    font_size: "36rpx",
                    top: "15rpx",
                    left: "245rpx",
                    height: "50rpx",
                    width: "50rpx"
                }
            })
        } else {
            this.setData({
                font_size: {
                    font_size: "28rpx",
                    top: "20rpx",
                    left: "245rpx",
                    height: "40rpx",
                    width: "40rpx"
                }
            })
        }
    }
})